home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Mops source
/
Toolbox classes
/
Window+
< prev
next >
Wrap
Text File
|
1999-02-06
|
5KB
|
234 lines
\ Window+ class - a window that supports views.
\ Oct 91 mrh Initial version.
\ May 92 mrh "New-style" controls
\ Feb 93 mrh Added sending idle: to the contView
\ Sept 93 mrh Revised for Control now being a View subclass.
need view
need scroller
rect aRect
:class WINDOW+ super{ window }
record
{ ptr ^contview \ points to view consisting of contents rect.
bool zoomflg
}
private
:m SetContViewBounds: { \ l t r b -- }
getRect: super -> b -> r -> t -> l
l t r 1+ b 1+ setBounds: [ get: ^contView ]
moved: [ get: ^contView ]
0 0 32000 dup put: tempRect update: tempRect
;m
public
:m SETZOOM: \ ( b -- ) Passed-in boolean indicates if this window
\ will be zoomable.
put: zoomFlg ;m
:m SETVIEW: { ^view -- }
^view put: ^contView ^base setWindow: [ ^view ] ;m
:m GETVIEW: get: ^contView ;m
:m NEW: { bndsRect tAddr tLen procID vis goAway ^view \ s255 -- }
get: alive ?EXIT \ Out if already alive
^view setView: self
\ ?disable_actW
tAddr tLen str255 -> s255
^base bndsrect s255
vis 1 and
get: zoomFlg 8 and procID +
inFront goAway 1 and
0 \ default is initially in front
get: color?
IF NewCWindow ELSE NewWindow THEN drop
initNewWindow: self
setContViewBounds: self
^view put: ^view_in_focus \ initial default
new: [ get: ^contView ] \ Fire up view object
;m
:m GETNEW: { resID ^view -- }
get: alive ?EXIT \ Out if already alive
^view setView: self
resID getnew: super
setContViewBounds: self
^view put: ^view_in_focus \ initial default
new: [ get: ^contView ] \ Fire up view object
;m
:m GROW:
grow: super set: super
setContViewBounds: self ;m
:m ZOOM:
zoom: super set: super
setContViewBounds: self ;m
:m ENABLE:
enable: super \ Note - we do this first to make sure the
\ current grafPort is set before the views
\ do anything.
get: ^contView enable: []
;m
:m DISABLE:
get: ^contView disable: [] disable: super
;m
:m (DRAW):
(draw): super
get: ^contview draw: []
;m
:m DRAW: (draw): self
( noclip ) ;m \ It seems that when I have scroll bars the
\ grow icon gets clipped out unless I call
\ noClip here. (The callLast routine
\ windupDraw: is where it's actually drawn).
\ IDLE: calls IDLE: on the contView (which will lead to it being called on
\ all views). We do this regardless of what view is in focus, to give
\ views a chance to do background stuff.
\ We ensure this window is the current Grafport, since the views
\ might want to look at the mouse position in local coordinates.
:m IDLE: { \ xx -- }
idle: super
pushPort set: self
get: ^contView idle: []
popPort ;m
:m CLOSE: \ Releases the views and closes the window
get: ^contView release: **
close: super ;m
:m CONTENT: \ Handles a content click. We call the contview to find
\ which view (if any) wants the click, then send CLICK:
\ to it.
active: self
IF noClip
get: ^contView view_for_click?: []
IF click: [] THEN
ELSE select: self
THEN ;m
:m KEY: \ ( c -- ) For typed keys, we send a KEY: to the
\ view in focus, if there is one.
nil?: ^view_in_focus
IF drop
ELSE key: [ get: ^view_in_focus ]
THEN ;m
:m TEST: { ^view -- }
screenbits true setGrow: self
true setZoom: self
100 100 400 200 put: aRect \ can't use tempRect - gets clobbered
aRect " Test" docWind true true ^view new: self ;m
:m TESTR: { resID ^view -- }
screenbits true setGrow: self
true setZoom: self
resID ^view getnew: self ;m
;class
endload
\ TESTING:
window+ WW
scroller S1 \ This will be the contview of WW
scroller S2 \ A child of S1 - another scroller!
20 20 150 200 setBounds: s2
view VV \ A child of S2
32 32 628 328 setBounds: vv
screenbits true setGrow: ww
true setZoom: ww
: DRW { \ l t r b -- } \ Draws a big X across the view area.
( clear: temprect ) get: tempRect -> b -> r -> t -> l
0 0 gotoxy r b LineTo
l b gotoxy r 0 LineTo ;
' drw setDraw: vv
: CLICK1 ." clicked s1!" cr ;
: CLICK2 ." clicked s2!" cr ;
' click1 setClick: s1 ' click2 setClick: s2
: GO
vv addView: s2 s2 addView: s1
s1 test: ww
-modeless
$ F5EF setMask: fEvent \ mask out key up
BEGIN
next: fevent
AGAIN
;
: GORES
vv addView: s2 s2 addView: s1
256 s1 testR: ww ;
\ endload
\ More testing - this sets up a Scroller.
scroller SS
button BB \ A child view which is a button
40 40 300 200 setBounds: ss
10 10 " Click here" init: bb
: Drawit draw: tempRect ; \ A draw handler which just draws the viewRect
: DrawSS draw: ss ; \ Draw handler for fWind for test
: Clicked
noclip
set: tw ." clicked " .id: [self] cr
\ Now we expand ss a bit to check if the scroll bars move and resize:
getBounds: ss
10 +
swap 20 + swap
setBounds: ss moved: ss ;
: contentClick \ New content click handler for fWind
click: ss drop ;
' drawit setDraw: ss
' clicked dup setclick: ss setclick: bb
: scrollerTest
bb addview: ss
ss test: ww
;